package com.hq.fxh.No1_Infromation.Video.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.hq.fxh.R;

import java.util.ArrayList;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created ${data}
 * @Email xlwenhao1858@sina.com
 */

public class Adapter_recycle_VideoDetail extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    Context mcontext;
    ArrayList<String> data;


    public Adapter_recycle_VideoDetail(Context context, ArrayList list) {
        mcontext = context;
        data = list;
    }

    public void setData(ArrayList<String> data) {
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewByViewType = getViewByViewType(viewType);
        return viewByViewType;
    }

    private RecyclerView.ViewHolder getViewByViewType(int type) {
        RecyclerView.ViewHolder viewHolder = null;
        View videoContentView = View.inflate(mcontext, R.layout.videodetail_play_item, null);
        View tuiJianView = View.inflate(mcontext, R.layout.videodetail_tuijian_item, null);

        if (type == 1) {
            viewHolder = new DetailsContentViewHolder(videoContentView);
        } else if (type == 2) {
            viewHolder = new TuijianViewHolder(tuiJianView);
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int itemViewType = holder.getItemViewType();

        if (itemViewType == 1) {
            DetailsContentViewHolder mholder = (DetailsContentViewHolder) holder;
            new Help_VideoDetils_Content(mcontext,  null).doIt();
           /* TopBannerViewHolder mholder = (TopBannerViewHolder) holder;
            new Help_Infor_Banner(mcontext, mholder, data).doForBanner();*/
        } else if (itemViewType == 2) {
            TuijianViewHolder mholder = (TuijianViewHolder) holder;
            new Help_VideoDetils_TuiJian(mcontext,  null) ;
        }

    }


    @Override
    public int getItemCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        int type = -1;
        if (position == 0) {
            type = 1;
        } else if (position == 1) {
            type = 2;
        } else if (position == 2) {
            type = 3;
        }
        return type;
    }




    public class DetailsContentViewHolder extends RecyclerView.ViewHolder {
        protected TextView tvVideoDatilTitle;
        protected TextView tvVideoDatilContent;
        protected TextView tvVideoDatilReadNum;
        protected TextView tvVideoDatilZhan;
        protected TextView tvVideoDatilZhiRu;

        public DetailsContentViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }

        public void initView(View rootView) {
            tvVideoDatilTitle = (TextView) rootView.findViewById(R.id.tv_VideoDatil_Title);
            tvVideoDatilContent = (TextView) rootView.findViewById(R.id.tv_VideoDatil_Content);
            tvVideoDatilReadNum = (TextView) rootView.findViewById(R.id.tv_VideoDatil_ReadNum);
            tvVideoDatilZhan = (TextView) rootView.findViewById(R.id.tv_VideoDatil_Zhan);
            tvVideoDatilZhiRu = (TextView) rootView.findViewById(R.id.tv_VideoDatil_ZhiRu);
        }
    }

    public class TuijianViewHolder extends RecyclerView.ViewHolder {

        protected ListView listVideoDetailTuiJian;

        public TuijianViewHolder(View itemView) {
            super(itemView);
            initView(itemView);
        }

        public void initView(View rootView) {
            listVideoDetailTuiJian = (ListView) rootView.findViewById(R.id.list_VideoDetail_TuiJian);
        }
    }

    public void setImageWH(ImageView image, int width, int height) {
        ViewGroup.LayoutParams layoutParams = image.getLayoutParams();
        layoutParams.height = height;
        layoutParams.width = width;

    }

}
